/*#include<bits/stdc++.h>
#define int long long
#define N 100005
#define il inline
#define Derta 3010
using namespace std;

bool f[N];
int pri[N], tot;
void init() {
	f[0] = f[1] = 1;
	for(int i = 2; i <= 100000; i++) {
		if(!f[i]) pri[++tot] = i;
		for(int j = 1; j <= tot && pri[j] * i <= 100000; j++) {
			f[pri[j] * i] = 1;
			if(i % pri[j] == 0) break;
		}
	}
	for(int i = 11; i <= 100000; i++)
		if(i % 20 != 3) f[i] = 1;
}

int T, n, m, ans;

il ABS(int x, int y) {
	return x > y ? x - y : y - x;
}

struct node {
	int x, y, val;
}a[N];

int h;
struct ask {
	int X1, Y1, X2, Y2, res;
}z[1000006];

int num;
struct op {
	int x, y, Num;
}s[1000006];

int Get[1000006];

struct ljm {
	int y, id, val;
};
vector<ljm>p[100006], G[100006];


bool cmp(node A, node B) {
	if(A.x != B.x) return A.x < B.x;
	else return A.y < B.y;
}

int lowbit(int x) {
	return x & (-x);
}

int c[100005];

void add(int x, int y) {
	for(int i = x; i <= 100000; i += lowbit(i)) 
		c[i] += y;
}

int query(int x) {
	int res = 0;
	for(int i = x; i; i -= lowbit(i)) 
		res += c[i];
	return res;
}
void Sol() {
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		cin >> a[i].x >> a[i].y;
		int X = a[i].x + a[i].y, Y = a[i].x - a[i].y;
		a[i].x = X; a[i].y = Y;
	} 
	for(int i = 1; i <= n; i++) cin >> a[i].val;
	
	sort(a + 1, a + n + 1, cmp);
	for(int i = 1; i < n; i++)
	for(int j = i + 1; j <= n; j++) {
		int D = max(ABS(x[i] - x[j]), ABS(y[i] - y[j]));
		if(f[D]) continue;
		if(y[i] <= y[j]) {
			int Ax = a[i].x - D, Ay = a[i].y - D, Bx = a[i].x + D, By = a[i].y + D, Cx = a[j].x - (D - 1), Cy = a[j].y - (D - 1);
			z[++h] = (node){Ax, Ay, Bx, By};
			z[++h] = (node){Cx, Cy, Bx, By};
		}
		else {
			int Ax = a[i].x + D, Ay = a[i].y - D, Bx = a[i].x - D, By = a[i].y + D, Cx = a[j].x + (0D - 1), Cy = a[j].y - (D - 1);
			z[++h] = (node){Bx, Ay, Ax, By};
			z[++h] = (node){Bx, Cy, Cx, By};
		}
	}
	for(int i = 1; i <= h; i++) {
		s[++num] = (op){X2, Y2};
		s[++num] = (op){X1 - 1, Y2};
		s[++num] = (op){X2, Y1 - 1};
		s[++num] = (op){X1 - 1, Y1 - 1};
	}
	
	for(int i = 1; i <= num; i++) {
		int X = s[i].x + Derta, Y = s[i].y + Derta;
		p[X].push_back((ljm){Y, i, 0});
	}
	
	for(int i = 1; i <= n; i++) {
		int x = a[i].x + Derta, y = a[i].y + Derta;
		G[x].push_back((ljm){y, 0, a[i].val}); 
	}
	
	for(int i = 1; i <= 100000; i++) {
		for(int j = 0; j < G[i].size(); j++) 
			add(G[i][j].y, G[i][j].val);
		for(int j = 0; j < p[i].size(); i++)
			ans[p[i][j].id] = query(p[i][j].y);
	}
	
	int now = 0;
	for(int i = 1; i <= h; i++) {
		now++; int A1 = Get[now];
		now++; int A2 = Get[now];
		now++; int A3 = Get[now];
		now++; int A4 = Get[now];
		z[i].res = A1 - A2 - A3 + A4;
	}
	
	now = 0;
	for(int i = 1; i < n; i++)
	for(int j = i + 1; j <= n; j++) {
		int D = max(ABS(x[i] - x[j]), ABS(y[i] - y[j]));
		if(f[D]) continue;
		int S = 0;
		now++; S += z[now].res;
		now++; S -= z[now].res;
		ans
	}
}
signed main(){
	ios::sync_with_stdio(0);
	init();
	cin >> T;
	while(T--) Sol();
	return 0;
}*/
#include<bits/stdc++.h>
#define int long long
#define N 1000005
#define il inline
using namespace std;

bool f[N];
int pri[N], tot;
void init() {
	f[0] = f[1] = 1;
	for(int i = 2; i <= 1000000; i++) {
		if(!f[i]) pri[++tot] = i;
		for(int j = 1; j <= tot && pri[j] * i <= 1000000; j++) {
			f[pri[j] * i] = 1;
			if(i % pri[j] == 0) break;
		}
	}

	for(int i = 11; i <= 1000000; i++)
		if(i % 20 != 3) f[i] = 1;
		
			for(int i = 1; i <= 100; i++)
		if(!f[i]) cout << i << " ";
	cout << endl;
}

int T, n, m, ans;

il ABS(int x) {
	return x > 0 ? x : -x;
}
struct node {
	int x, y, val;
}a[N];


bool cmp(node A, node B) {
	if(A.x != B.x) return A.x < B.x;
	else return A.y < B.y;
}

il Get(int i, int j) {
	return abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y);
}

//map<int, map<int, map<int, int> > >G;

void Sol() {
	
	ans = 0;
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		cin >> a[i].x >> a[i].y;
	} 
	for(int i = 1; i <= n; i++) cin >> a[i].val;
	
	//sort(a + 1, a + n + 1, cmp);
	/*for(int i = 1; i < n; i++)
	for(int j = i + 1; j <= n; j++) {
		int D = Get(i, j);
		if(f[D]) continue;
		for(int k = 1; k <= n; k++) {
			if(k == i || k == j) continue; 
			if(Get(k, i) <= D && D <= Get(j, k)) {
				
				//cout << "look : " << i << " " << j << " " << k << endl;
				ans += a[i].val + a[j].val + a[k].val;
				
			}
		}
	}*/
	for(int i = 1; i < n; i++)
	for(int j = i + 1; j <= n; j++)
	for(int k = j + 1; k <= n; k++) {
		int D1 = Get(i, j), D2 = Get(i, k), D3 = Get(j, k);
		if(D2 <= D1 && D1 <= D3 || D3 <= D1 && D1 <= D2) {
			if(!f[D1]) ans += a[i].val + a[j].val + a[k].val;
		} 
		else if(D1 <= D2 && D2 <= D3 || D3 <= D2 && D2 <= D1) {
			if(!f[D2]) ans += a[i].val + a[j].val + a[k].val;
		}
		else {
			if(!f[D3]) ans += a[i].val + a[j].val + a[k].val;
		}
	}
	cout << ans << endl;
}
signed main(){
	freopen("chess.in", "r", stdin);
	freopen("chess.out", "w", stdout);
	ios::sync_with_stdio(0);
	init();
	cin >> T;
	while(T--) Sol();
	return 0;
}

/*
1
3 5
1 1
2 2
3 3
1 2 3
*/

